//
//  HDragItem.m
//  HDragImageDemo
//
//  Created by 黄江龙 on 2018/9/5.
//  Copyright © 2018年 huangjianglong. All rights reserved.
//

#import "HDragItem.h"

@interface HDragItem ()

@property (nonatomic, strong) UIButton *deleteBtn;

@end

@implementation HDragItem

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.userInteractionEnabled = YES;
        self.layer.masksToBounds = YES;
        self.contentMode = UIViewContentModeScaleAspectFill;
        
    }
    return self;
}

- (void)deleteAction:(UIButton *)sender
{
    if (self.deletePhotoBlock) {
        self.deletePhotoBlock(self);
    }
}

- (void)setIsAdd:(BOOL)isAdd
{
    _isAdd = isAdd;
    if (!isAdd) {
        
//        UIButton *tapBtn = [[UIButton alloc] init];
//        tapBtn.backgroundColor = [UIColor clearColor];
//        [tapBtn addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:tapBtn];
//        [tapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.edges.equalTo(self);
//        }];
        
        self.deleteBtn = [[UIButton alloc] init];
        [self.deleteBtn setBackgroundImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
        [self.deleteBtn addTarget:self action:@selector(deleteAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.deleteBtn];
        [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.equalTo(self);
            make.width.height.equalTo(@26);
        }];
    }
}

- (void)tapAction:(UITapGestureRecognizer *)tap
{
    if (self.tapHandle) {
        self.tapHandle(self);
    }
}

- (void)setDeleteAlpha:(CGFloat)deleteAlpha
{
    self.deleteBtn.alpha = deleteAlpha;
}

@end
